using System;
using System.Runtime.InteropServices;
using System.Threading;

namespace OF.Security.Utils
{
	public static class UuidHelper
	{
		[DllImport("rpcrt4.dll", SetLastError = true)]
		private static extern int UuidCreateSequential(out Guid guid);

		public static Guid NewUuid()
		{
			Guid result;
			lock (typeof(UuidHelper))
			{
				int num = UuidHelper.UuidCreateSequential(out result);
				if (num == 0)
				{
					result = Guid.NewGuid();
				}
				Thread.Sleep(1);
			}
			return result;
		}

		public static string NewUuidString()
		{
			byte[] array = UuidHelper.NewUuid().ToByteArray();
			for (int i = 0; i < 8; i++)
			{
				byte b = array[15 - i];
				array[15 - i] = array[i];
				array[i] = b;
			}
			return new Guid(array).ToString();
		}
	}
}
